﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Shop_DAL
    {
        #region Shop页面下拉框
        /// <summary>
        /// 
        /// </summary>
        /// <returns>List<Shop_Model></returns>
        public List<Shop_Model> Drop_Data()
        {
            string sql = "select * from Category";
            SqlDataReader sqlData = DBHelper.ExecuteReader(sql);
            List<Shop_Model> shop_Models = new List<Shop_Model>();
            if (sqlData.HasRows)
            {
                while (sqlData.Read())
                {
                    Shop_Model Model = new Shop_Model();
                    Model.Category_ID = Convert.ToInt32(sqlData["Category_ID"]);
                    Model.Category_Name = sqlData["Category_Name"].ToString();
                    shop_Models.Add(Model);
                }
            }
            return shop_Models;
        }
        #endregion
        #region Shop页面内容绑定(下拉框查询)
        /// <summary>
        /// int
        /// </summary>
        /// <returns>List<Shop_Model></returns>
        public List<Shop_Model> Products_Select(int CategoryID)
        {
            string sql = "select * from Products inner join Category on Products.Products_CategoryID=Category.Category_ID";
            List<Shop_Model> shop_Models = new List<Shop_Model>();
            if (CategoryID!=0)
            {
                sql +=$" and Products.Products_CategoryID={CategoryID}";
            }
            SqlDataReader sqlDataReader = DBHelper.ExecuteReader(sql);
            if (sqlDataReader.HasRows)
            {
                while (sqlDataReader.Read())
                {
                    Shop_Model models = new Shop_Model
                    {
                        Products_ID = Convert.ToInt32(sqlDataReader["Products_ID"]),
                        Products_Name = sqlDataReader["Products_Name"].ToString(),
                        Products_price = Convert.ToInt32(sqlDataReader["Products_price"]),
                        Products_Remark = sqlDataReader["Products_Remark"].ToString(),
                        Products_imgUrl1 = sqlDataReader["Products_imgUrl1"].ToString(),
                        Products_imgUrl2 = sqlDataReader["Products_imgUrl2"].ToString(),
                        Products_imgUrl3 = sqlDataReader["Products_imgUrl3"].ToString(),
                        Products_imgUrl4 = sqlDataReader["Products_imgUrl4"].ToString(),
                        Products_State = Convert.ToInt32(sqlDataReader["Products_State"]),
                        Products_CategoryID = Convert.ToInt32(sqlDataReader["Products_CategoryID"]),
                        Category_Name = sqlDataReader["Category_Name"].ToString()
                };
                    shop_Models.Add(models);
                }
            }
            return shop_Models;
        }
        #endregion
    }
}
